package group.hhsw.user.controller;

import group.hhsw.common.model.params.LoginParam;
import group.hhsw.common.model.params.RegisterParam;
import group.hhsw.common.model.params.SetUserParam;
import group.hhsw.common.utils.Result;
import group.hhsw.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/getAllUsers")
    public Result getAllUsers() {
        return Result.success(userService.getAllUsers());
    }

    @GetMapping("/getArea/{id}")
    public String getArea(@PathVariable("id") Long id) {
        return userService.getUserArea(id);
    }

    @GetMapping("/getLabel/{id}")
    public String getLabel(@PathVariable("id") Long id) {
        return userService.getUserLabel(id);
    }

    @PostMapping("/login")
    public Result login(@RequestBody LoginParam loginParam) {
        return userService.login(loginParam);
    }

    @GetMapping("/currentUser")
    public Result currentUser(@RequestHeader("Authorization") String token) {
        return userService.currentUser(token);
    }

    @GetMapping("/checkLogin")
    public Boolean checkLogin(@RequestHeader("Authorization") String token) {
        return userService.checkLogin(token);
    }

    @PostMapping("/register")
    public Result register(@RequestBody RegisterParam registerParam) {
        return userService.register(registerParam);
    }

    @GetMapping("/logout")
    public Result logout(@RequestHeader("Authorization") String token) {
        return userService.logout(token);
    }

    @PostMapping("/updateUser")
    public Result updateUser(@RequestBody SetUserParam setUserParam) {
        return userService.updateUser(setUserParam);
    }

    @GetMapping("/whitelistDetection/{id}")
    public Boolean whitelistDetection(@PathVariable Long id) {
        return userService.whitelistDetection(id);
    }

}
